<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/18
 * Time: 14:28
 */
namespace app\home\model;

use think\Model;
use traits\model\SoftDelete;
use app\common\model\User;
use app\home\model\Deploy;

class ProjectNeed extends Model
{
    use SoftDelete;
    // 定义时间戳字段名
    protected $createTime = 'ctime';
    protected $updateTime = '';
    protected $deleteTime = 'deleted';

    public static $statusCode = [
        0  => '筹备中',
        1  => '待开发',
        2  => '开发中',
        3  => '待测试',
        4  => '测试中',
        5  => '待上线',
        6  => '已上线'
    ];

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    public function info()
    {
        $this->hasMany('NeedInfo','needs_id','id');
    }

    public static function getStatusAttr($index){
        return self::$statusCode[$index];
    }

    public static function getPriorityAttr($id){
        return Deploy::where('id',$id)->value('name');
    }

    public static function getPtimeAttr($time){
        return $time ? date('Y-m-d', $time) : '';
    }

    public static function getCtimeAttr($time){
        return $time ? date('Y-m-d', $time) : '';
    }

    public static function getEtimeAttr($time){
        return $time ? date('Y-m-d', $time) : '';
    }

    public static function getTypeAttr($id){
        return Deploy::where('id',$id)->value('name');
    }

    public static function getproductIdAttr($id){
        return \app\home\model\Project::where('id',$id)->value('name');
    }

    public static function getCreatorAttr($id){
        return User::where('id',$id)->value('nick');
    }

    public function getFrontUserAttr($id){
        return User::where('id',$id)->value('nick');
    }

    public function getAfterUserAttr($id){
        return User::where('id',$id)->value('nick');
    }

    public static function getBlockIdAttr($id){
        return \app\home\model\Block::where('id',$id)->value('name');
    }

    public static function getIssueIdAttr($id){
        return \app\home\model\IssueVersions::where('id',$id)->value('name');
    }

    public function getSourceAttr($id){
        return Deploy::where('id',$id)->value('name');
    }
    public function getDeptidAttr($index){
        $dept = ['前端', '后端', '产品经理', '测试', '运维','管理员'];
        return $dept[$index];
    }
}